package {
	import org.flixel.*;
	
	public class Spawner {
		private var _spawn_time:Number;
		private var _timer:FlxTimer;
		private var _group:FlxGroup;

		public function Spawner(Group:FlxGroup) {
			_group = Group;
		}
		
		public function create(SpawnTime:Number):void 
		{
			_spawn_time = SpawnTime;
			_timer = new FlxTimer(_spawn_time, Spawn);
			FlxG.addTimer(_timer);
		}
		
		public function start():void 
		{
			if(_timer)
				_timer.start();
		}
		
		private function Spawn():void 
		{
			_group.add(Enemy.getEnemy(FlxG.width, FlxU.random() * (FlxG.height - 20)));
		}
		
		public function destroy():void  {
			_timer.destroy();
			_group.destroy();
		}
	}
}